package com.haozi.ehub.admin.handler;

import com.alibaba.fastjson.JSONObject;
import com.haozi.ehub.core.enums.HttpEunm;
import com.haozi.ehub.core.util.CodeUtils;
import com.haozi.ehub.core.util.ReturnDataUtils;
import com.haozi.ehub.entity.entities.ReturnData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 未登录
 * @author ：terry
 * @date ：Created in 2020/6/23 14:07
 * @description：TODO
 * @version: 1.0
 */
@Deprecated
@Slf4j
@SuppressWarnings(value = "all")
public class SecurityAuthenticationEntryPointHandler implements AuthenticationEntryPoint {

    @Override
    public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException {
        log.info("Into securityAuthenticationEntryPointHandler");
        String msg = HttpEunm.UNLOGIN.getMsg();
        ReturnData returnData = ReturnDataUtils.returnDataFail(HttpStatus.FORBIDDEN, msg);
        String json = JSONObject.toJSONString(returnData);
        httpServletResponse.setContentType(CodeUtils.HTTP_CONTENT_TYPE_JSON);
        httpServletResponse.getWriter().write(json);
    }
}
